<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui" xml:lang="en" lang="en">
	<h:head />
	<body>
		<ui:composition template="/rootWeb.xhtml">
	    <ui:define name="header">
	        <title>模具管理</title>
	        <script type="text/javascript">
	        	//页面载入时注册
	        	jQuery(document).ready(function(){
	        		//鼠标移入
					jQuery("#moldTable_data tr").live("mouseover", function() {
					  	jQuery(this).css("background-color","#CCCCCC");
					});
					//鼠标移出
					jQuery("#moldTable_data tr").live("mouseout", function() {
					  	jQuery(this).css("background-color","white");
					});
				});
				function onAddMold(xhr, status, args){
					if(args.error){
						alert(args.error);
						return ;
					}
					addMoldDlg.show();
				}
				function onSaveMoldComplete(xhr, status, args){
					if(args.error){
						alert(args.error);
						return ;
					}
					alert(args.msg);
					addMoldDlg.hide();
				}
				function onUpdateMoldComplete(xhr, status, args){
					if(args.error){
						alert(args.error);
						return ;
					}
					alert(args.msg);
					updateMoldDlg.hide();
				}
				//重置
				function resetQueryCondition(){
					jQuery("#queryMoldFactory").val("");
					jQuery("#queryMoldCreateDate_input").val("");
					jQuery("#queryMoldName").val("");
					jQuery("#queryMoldSpecification").val("");
					jQuery("#queryMoldPerWeight_input").val("");
					jQuery("#queryMoldThickness_input").val("");
					jQuery("#queryMoldState").val("");
				}
				
				//点击新增按钮调用 
				function onAddMoldSeries(xhr, status, args){
					if(args.error){
						alert(args.error);
						return ;
					}
					addMoldSeriesDlg.show();
				}
				//保存完成后调用 
				function onSaveMoldSeriesComplete(xhr, status, args){
					if(args.error){
						alert(args.error);
						return ;
					}
					alert(args.msg);
					addMoldSeriesDlg.hide();
				}
				//点击修改按钮调用 
				function onUpdateMoldSeries(xhr, status, args){
					if(args.error){
						alert(args.error);
						return ;
					}
					updateMoldSeriesDlg.show();
				}
				//点击删除按钮调用 
				function onDeleteMoldSeries(xhr, status, args){
					if(args.error){
						alert(args.error);
						return ;
					}
					deleteMoldSeriesDlg.show();
				}
				//更新完成后调用 
				function onUpdateMoldSeriesComplete(xhr, status, args){
					if(args.error){
						alert(args.error);
						return ;
					}
					alert(args.msg);
					updateMoldSeriesDlg.hide();
				}
			</script>
	    </ui:define>
	    <ui:define name="body">
	    	<h:form id="form" prependId="false">
				<p:layout style="min-width:400px;min-height:500px;" id="layout">
					<p:layoutUnit position="north" size="100" resizable="true" collapsible="true" style="border: 0px solid #D5D5D5;"> 
						<div style="white-space:nowrap;width: 100%;overflow:auto"> 
						<h:panelGrid id="queryMoldGrid" columns="8" style="width: 100%" >
							<h:outputLabel for="queryMoldFactory" value="模具厂：" />
		    				<p:inputText id="queryMoldFactory" value="#{moldManageAction.queryMold.factoryName}" size="15"/>
							<h:outputLabel for="queryMoldCreateDate" value="开模日期："/>
		    				<p:calendar id="queryMoldCreateDate" value="#{moldManageAction.queryMold.createDate}" size="15"
		    					timeZone="GMT+8" pattern="yyyy-MM-dd" showButtonPanel="true" navigator="true"/>
							<h:outputLabel for="queryMoldName" value="模具名称："/>
		    				<h:selectOneMenu id="queryMoldName" value="#{moldManageAction.queryMold.moldName}" style="width: 120px">  
		    				 	<f:selectItem itemLabel="请选择"  itemValue=""/>
				                <f:selectItems value="#{moldManageAction.moldNameItems}"/>
				            </h:selectOneMenu>
							<h:outputLabel for="queryMoldSpecification" value="模具规格："/>
		    				<p:inputText id="queryMoldSpecification" value="#{moldManageAction.queryMold.moldSpecification}" size="15"/>
							<h:outputLabel for="queryMoldPerWeight" value="模具支重："/>
							<p:spinner id="queryMoldPerWeight"    value="#{moldManageAction.queryMold.moldPerWeight}" min="0.00" stepFactor="0.01" size="13"/>
							<h:outputLabel for="queryMoldThickness" value="模具壁厚："/>
							<p:spinner id="queryMoldThickness"    value="#{moldManageAction.queryMold.moldThickness}" min="0.00" stepFactor="0.01" size="13"/>
							<h:outputLabel for="queryMoldState" value="模具状态："/>
							<h:selectOneMenu id="queryMoldState" value="#{moldManageAction.queryMold.moldState}" style="width: 120px">  
		    				 	<f:selectItem itemLabel="请选择"  itemValue=""/>
				                <f:selectItems value="#{moldManageAction.moldStateItems}"/>
				            </h:selectOneMenu>
		    				<h:panelGrid columns="1">
		    					<p:commandButton value="重置" onclick="resetQueryCondition()" style="width: 70px"/>
		    				</h:panelGrid>
		    				<h:panelGrid columns="3"> 
		    				    <p:commandButton value="查询" action="#{moldManageAction.doFilterMoldList}" update=":form:moldTable"/>
		    				    <p:commandButton value="新增" action="#{moldManageAction.addMold}" oncomplete="onAddMold(xhr, status, args);" update=":form:addMoldPanel"/>
			    			    <p:commandButton value="导入导出"/>
		    			    </h:panelGrid>
						</h:panelGrid>
						</div>
    				</p:layoutUnit> 
					<p:layoutUnit position="west" resizable="true" size="100"  minSize="200" maxSize="350" >  
						<div align="left">
				        	<p:commandButton value="新增" action="#{moldManageAction.addMoldSeries}" oncomplete="onAddMoldSeries(xhr, status, args)" update=":form:addMoldSeriesDlgID"/>
				        	<p:spacer width="5"/>
				        	<p:commandButton value="修改"  action="#{moldManageAction.setUpdateSeries}" oncomplete="onUpdateMoldSeries(xhr, status, args)" update=":form:updateMoldSeriesDlgID"/>
				        	<p:spacer width="5"/>
				        	<p:commandButton value="删除"  action="#{moldManageAction.setUpdateSeries}" oncomplete="onDeleteMoldSeries(xhr, status, args)" update=":form:updateMoldSeriesDlgID,:form:deleteMoldSeriesDlgID"/>
				        </div>
				        <p:tree value="#{moldManageAction.seriesTree}" var="node"  id="moldSeriesTree" style="border: 0px solid #D5D5D5;"
				        	selectionMode="single"  selection="#{moldManageAction.selectedNode}">  
				        	<p:ajax event="select" listener="#{moldManageAction.onNodeSelect}"   update=":form:moldTable,:form:queryMoldGrid"/>
				        	<p:ajax event="unselect"  listener="#{moldManageAction.onNodeUnselect}"  update=":form:moldTable,:form:queryMoldGrid"/> 
					        <p:treeNode>  
					            <h:outputText value="#{node.seriesName}" />  
					        </p:treeNode>  
					    </p:tree>   
				    </p:layoutUnit>
					<p:layoutUnit position="center" style="border: 0px solid #D5D5D5;">  
				          <p:dataTable id="moldTable" value="#{moldManageAction.moldList}" var="mold" rowKey="mold" emptyMessage="没有记录！"
			    				paginator="true" rows="5"  	rowsPerPageTemplate="5,10,15"	paginatorAlwaysVisible="true" 	paginatorPosition="bottom" currentPageReportTemplate="查询到{totalRecords}条记录，本页显示{startRecord}～{endRecord}；第{currentPage}/{totalPages}页"
                 				paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"   >
			    			<p:column headerText="系列">#{mold.moldSeries.seriesName}</p:column>
			    			<p:column headerText="品名">
			    				<h:selectOneMenu value="#{mold.moldName}" disabled="true">  
					                <f:selectItems value="#{moldManageAction.moldNameItems}"/>
					            </h:selectOneMenu>
			    			</p:column>
			    			<p:column headerText="型号">#{mold.moldNumber}</p:column>
			    			<p:column headerText="规格">#{mold.moldSpecification}</p:column>
			    			<p:column headerText="壁厚" style="text-align:right;">#{mold.moldThickness}</p:column>
			    			<p:column headerText="支重" style="text-align:right;">#{mold.moldPerWeight}</p:column>
			    			<p:column headerText="累积产量" style="text-align:right;">#{mold.totalYield}</p:column>
			    			<p:column headerText="状态">
			    				<h:selectOneMenu value="#{mold.moldState}" disabled="true">  
					                <f:selectItems value="#{moldManageAction.moldStateItems}"/>
					            </h:selectOneMenu>
					            <h:outputText rendered="#{mold.moldState eq 'MoldState_producing'}" value="#{mold.machine.machineNumber}"></h:outputText>
			    			</p:column>
			    			<p:column headerText="最近使用日期" style="text-align:center;">
			    			    <h:outputText value="#{mold.lastUsedDate}"   styleClass="outputInfoFont">
	    							<f:convertDateTime pattern="yyyy-MM-dd" timeZone="GMT+8" />
	    						</h:outputText>
	    					</p:column>
			    			<p:column headerText="操作">
			    				<p:commandLink value="查看" style="color:red;margin-right:5px" action="#{moldManageAction.setViewMold(mold)}"
			    					update=":form:viewMoldDlgID" oncomplete="viewMoldDlg.show();"/>
			    				<p:commandLink value="修改" action="#{moldManageAction.setUpdateMold(mold)}" oncomplete="updateMoldDlg.show();"
			    					update=":form:updateMoldDlgID" style="color:red;margin-right:5px"/>
			    				<p:commandLink value="删除" action="#{moldManageAction.setUpdateMold(mold)}" oncomplete="deleteMoldDlg.show();"
			    					update=":form:updateMoldDlgID,:form:deleteMoldDlgID" style="color:red;margin-right:5px"/>
			    				<p:commandLink value="氮化"   action="#{moldManageAction.changMoldState(mold,'MoldState_Nitride')}" oncomplete="changeMoldStateConfirmDialog.show()"
			    					update=":form:updateMoldDlgID,:form:changeMoldStateConfirmDialogID" style="color:red;margin-right:5px"
			    					rendered="#{mold.moldState ne 'MoldState_Nitride'  }"/>
			    				<p:commandLink value="入库"  action="#{moldManageAction.changMoldState(mold,'MoldState_wait')}" oncomplete="changeMoldStateConfirmDialog.show()"
			    					update=":form:updateMoldDlgID,:form:changeMoldStateConfirmDialogID" style="color:red;margin-right:5px"
			    					rendered="#{mold.moldState ne 'MoldState_wait' }"/>
			    				<p:commandLink value="领用"  action="#{moldManageAction.changMoldState(mold,'MoldState_producing')}" oncomplete="moldTakingDlg.show()"
			    					update=":form:updateMoldDlgID" style="color:red;margin-right:5px"
			    					rendered="#{mold.moldState ne 'MoldState_producing' }"/>
			    				<p:commandLink value="报废"  action="#{moldManageAction.changMoldState(mold,'MoldState_Scrapped')}" oncomplete="changeMoldStateConfirmDialog.show()"
			    					update=":form:updateMoldDlgID,:form:changeMoldStateConfirmDialogID" style="color:red;margin-right:5px"
			    					rendered="#{mold.moldState ne 'MoldState_Scrapped' }"/>
			    				<p:commandLink value="返修"  action="#{moldManageAction.changMoldState(mold,'MoldState_Depot')}" oncomplete="moldDepotDlg.show()"
			    					update=":form:updateMoldDlgID,:form:moldDepotDlgID" style="color:red;margin-right:5px"
			    					rendered="#{mold.moldState ne 'MoldState_Depot' }"/>
							</p:column>
			    		</p:dataTable>
				    </p:layoutUnit>
				</p:layout>
				<ui:include src="addAndUpdateMold.xhtml"></ui:include>
				<!-- 删除模具系列-->
				<p:confirmDialog id="deleteMoldSeriesDlgID" message="确认删除模具系列吗?"
					header="删除模具系列" severity="alert" widgetVar="deleteMoldSeriesDlg">
					<p:commandButton value="确定" update=":form:moldTable,:form:moldSeriesTree" action="#{moldManageAction.doDeleteMoldSeries}"
						oncomplete="if(this.args.error){alert(this.args.error)}else{alert(this.args.msg);}deleteMoldSeriesDlg.hide();"  />
					<p:commandButton value="取消" onclick="deleteMoldSeriesDlg.hide()" type="button" />
				</p:confirmDialog>
				<!-- 删除模具 -->
				<p:confirmDialog id="deleteMoldDlgID" message="确认删除模具吗?"
					header="删除模具" severity="alert" widgetVar="deleteMoldDlg">
					<p:commandButton value="确定" update=":form:moldTable" action="#{moldManageAction.doDeleteMold}"
						oncomplete="if(this.args.error){alert(this.args.error)}else{alert(this.args.msg);deleteMoldDlg.hide();}"  />
					<p:commandButton value="取消" onclick="deleteMoldDlg.hide()" type="button" />
				</p:confirmDialog>
				<!-- 修改模具系列 -->
				<p:dialog id="updateMoldSeriesDlgID" header="修改模具系列" widgetVar="updateMoldSeriesDlg" modal="true" 
					resizable="false">
						<h:panelGrid columns="2" >
							<h:outputLabel for="seriesName_update" value="名称:" />
							<p:inputText value="#{moldManageAction.updateSeries.seriesName}" id="seriesName_update"  maxlength="100"/>
							<p:spacer/><p:spacer/>
							
							<h:outputLabel for="seriesDesc_update" value="描述:" />
							<p:inputText value="#{moldManageAction.updateSeries.seriesRemark}" id="seriesDesc_update"  maxlength="250"/>
							<p:spacer/><p:spacer/>
			            	
			            	<f:facet name="footer">
			    				<p:commandButton value="更新" action="#{moldManageAction.updateSeries}" update=":form:moldSeriesTree"
			    						oncomplete="onUpdateMoldSeriesComplete(xhr, status, args)"/>
			    			</f:facet>
						</h:panelGrid>
				</p:dialog>
				<!-- 新增模具系列 -->
				<p:dialog id="addMoldSeriesDlgID" header="增加模具系列" widgetVar="addMoldSeriesDlg" modal="true"  resizable="false">
						<h:panelGrid columns="2" >
							<h:outputLabel for="seriesName" value="名称:" />
							<p:inputText value="#{moldManageAction.addSeries.seriesName}" id="seriesName"  maxlength="100"/>
							<p:spacer/><p:spacer/>
							
							<h:outputLabel for="seriesCode" value="代码:" />
							<p:inputText value="#{moldManageAction.addSeries.seriesCode}" id="seriesCode"  maxlength="10"/>
							<p:spacer/><p:spacer/>
							
							<h:outputLabel for="seriesDesc" value="描述:" />
							<p:inputText value="#{moldManageAction.addSeries.seriesRemark}" id="seriesDesc"  maxlength="250"/>
							<p:spacer/><p:spacer/>
							
			            	<f:facet name="footer">
			    				<p:commandButton value="保存" action="#{moldManageAction.saveMoldSeries}" update=":form:moldSeriesTree"
			    						oncomplete="onSaveMoldSeriesComplete(xhr, status, args)"/>
			    			</f:facet>
						</h:panelGrid>
				</p:dialog>
				
				<!-- 模具领用 -->
				<p:dialog id="moldTakingDlgID" header="模具领用" widgetVar="moldTakingDlg" modal="true" resizable="false" >
					<h:panelGrid style="width: 100%" columns="3">
						<h:outputLabel for="machineID" value="机台："/>
						<p:inputText id="machineID" value="#{moldManageAction.selectedMachine.machineNumber}" readonly="true"/>
						<p:commandLink value="选择" style="color:RED" oncomplete="machineDlg.show()" update=":form:machineDlgID" action="#{moldManageAction.showMachineList}"/>
					</h:panelGrid>
					<f:facet name="footer">
						<p:commandButton value="确定" update=":form:moldTable" action="#{moldManageAction.doChangeMoldState}"
							oncomplete="if(this.args.error){alert(this.args.error)}else{alert(this.args.msg);moldTakingDlg.hide();}"  />
						<p:commandButton value="取消" onclick="moldTakingDlg.hide()" type="button" />
					</f:facet>
				</p:dialog>
				
				<p:dialog id="machineDlgID" header="选择机台" widgetVar="machineDlg" modal="true" resizable="false" >
					<p:dataTable id="machineTable" value="#{moldManageAction.machineList}" var="machine" rowKey="#{machine}" emptyMessage="没有记录！" selection="#{moldManageAction.selectedMachine}"
			    		paginator="true" rows="10"  	rowsPerPageTemplate="5,10,15"	paginatorAlwaysVisible="false" 	paginatorPosition="bottom" currentPageReportTemplate="{currentPage} / {totalPages}"
                 		paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"   >
                 		<p:column selectionMode="single"/>
                 		<p:column headerText="机台编号">#{machine.machineNumber}</p:column>
               			<p:column headerText="机台状态">
               				<h:selectOneMenu value="#{machine.machineState}" disabled="true" style="width:120px">  
				                <f:selectItems value="#{moldManageAction.machineStateItems}"/>
				            </h:selectOneMenu>
               			</p:column>
               			<p:column headerText="描述">#{machine.machineRemark}</p:column>
                 	</p:dataTable>
					<f:facet name="footer">
						<p:commandButton value="确定" action="#{moldManageAction.setMoldMachineProp}" 
							update=":form:machineID" oncomplete="machineDlg.hide()"/>
					</f:facet>
				</p:dialog>
				
				<!-- 模具返修-->
				<p:dialog id="moldDepotDlgID" header="模具返修" widgetVar="moldDepotDlg" modal="true" resizable="false" >
					<p:outputPanel style="width: 100%" >
						<h:outputLabel for="depotDate" value="返修日期："/>
						<p:calendar id="depotDate" value="#{moldManageAction.updateMold.depotDate}" 
		    					timeZone="GMT+8" pattern="yyyy-MM-dd" showButtonPanel="true" navigator="true"/>
					</p:outputPanel>
					<f:facet name="footer">
						<p:commandButton value="确定" update=":form:moldTable" action="#{moldManageAction.doChangeMoldState}"
							oncomplete="if(this.args.error){alert(this.args.error)}else{alert(this.args.msg);moldDepotDlg.hide();}"  />
						<p:commandButton value="取消" onclick="moldDepotDlg.hide()" type="button" />
					</f:facet>
				</p:dialog>
				
				<!-- 更改模具状态 -->
				<p:confirmDialog id="changeMoldStateConfirmDialogID"
					message="#{moldManageAction.changeMoldStateMessage}"
					header="#{moldManageAction.changeMoldStateHeaderText}" severity="alert" widgetVar="changeMoldStateConfirmDialog">
					<p:commandButton value="确定" update=":form:moldTable" action="#{moldManageAction.doChangeMoldState}"
						oncomplete="if(this.args.error){alert(this.args.error)}else{changeMoldStateConfirmDialog.hide();}"  />
					<p:commandButton value="取消" onclick="changeMoldStateConfirmDialog.hide()" type="button" />
				</p:confirmDialog>
				
			</h:form>
	    </ui:define>
		</ui:composition>
	</body>
</html>
